package mest.service.Modeling.Impl;

import com.alibaba.fastjson.JSON;
import mest.VO.hank.model.customer_fileModel;
import mest.dao.Modeling.ICustomerFileDao;
import mest.entity.customer_file;
import mest.entity.customer_type;
import mest.service.Modeling.ICustomerFileService;
import mest.util.ResultObj;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @auther Machenike
 * @create 2019-11-15 15:42
 */

@Service
@Transactional(rollbackFor=Exception.class)
public class CustomerFileServiceImpl implements ICustomerFileService {

    @Resource
    private ICustomerFileDao icfd;

    @Override
    public String insertCustomerFile(customer_file ct,String theirDb)   {
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            icfd.insertCustomerFile(ct,theirDb);
            map.put("code",0);
            map.put("msg","添加成功");
            return JSON.toJSONString(map);
        } catch (Exception e) {
            e.printStackTrace();
            if (e.getClass().getName().equals("org.springframework.dao.DuplicateKeyException")) {
                map.put("msg","编码重复");
                return JSON.toJSONString(map);
            }
                map.put("msg", "添加失败");
            return JSON.toJSONString(map);
        }

    }

    @Override
    public int selectCount(String theirDb) {
        return icfd.selectCount(theirDb);
    }

    @Override
    public List<customer_file> findCustomerFilePage(int index, int pageSize,String theirDb) {
        return icfd.findCustomerFilePage((index-1)*pageSize,pageSize, theirDb);
    }

    @Override
    public int delModel(Integer id,String theirDb) {
        return icfd.delModel(id,theirDb);
    }

    @Override
    public List<customer_fileModel> queryAll(Integer index, Integer pageSize, String record,String theirDb) {
        return icfd.queryAllModel((index-1)*pageSize,pageSize , record,theirDb);
    }

    @Override
    public int findCount(String record,String theirDb) {
        return icfd.findCount(record,theirDb);
    }

    @Override
    public String updateByOne(customer_file record, String theirDb) {
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            icfd.updateByPrimaryKeySelective(record,theirDb);
            map.put("code",0);
            map.put("msg","添加成功");
        }catch (Exception e){
            e.printStackTrace();
            if (e.getClass().getName().equals("org.springframework.dao.DuplicateKeyException")) {
                map.put("msg","编码重复");
            }
            map.put("msg","添加失败");
        }
        return JSON.toJSONString(map);
    }
}
